<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">{{["未接单", "接单人", "已完成", "已取消"][status-1]}}</text>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		<template v-if="status==1">
			<view class="box margin20 padding40" v-for="(item, index) in list" :key="index">
				<view class="label" style="padding-top: 0;">店铺名称：{{item.shopName}}</view>
				<view class="label">{{item.homecareName}}</view>
				<view class="label">联系方式：{{item.phoneNo}}</view>
				<view class="label">上门时间：{{item.createTime || "无"}}</view>
				<view class="label">预付定金：{{item.deposit}}元</view>
				<view class="label">地区：{{item.area}}</view>
				<view class="label">地址：{{item.address}}</view>
				<view class="label">说明情况: {{item.description || "无"}}</view>
				<view class="flex-center margin50">
					<view class="btn" style="width: 200rpx; margin: 0 15rpx;" @click="cancel(item.id)">取消</view>
				</view>
			</view>
		</template>
		<template v-if="status==2">
			<view class="box margin20 padding40" v-for="(item, index) in list" :key="index">
				<view class="label" style="padding-top: 0;">店铺名称：{{item.shopName}}</view>
				<view class="label">{{item.homecareName}}</view>
				<view class="label">联系方式：{{item.phoneNo}}</view>
				<view class="label">上门时间：{{item.createTime || "无"}}</view>
				<view class="label">发表时间：{{item.visitTime}}</view>
				<view class="label">预付定金：{{item.deposit}}元</view>
				<view class="label">地区：{{item.area}}</view>
				<view class="label">地址：{{item.address}}</view>
				<view class="label">说明情况: {{item.description || "无"}}</view>
				<view class="flex-center margin50">
					<view class="btn" style="width: 200rpx; margin: 0 15rpx;" @click="$tools.route('./describetion', item.workerId)">接单人</view>
				</view>
			</view>
		</template>
		<template v-if="status==3">
			<view class="box margin20 padding40" v-for="(item, index) in list" :key="index">
				<view class="label" style="padding-top: 0;">店铺名称：{{item.shopName}}</view>
				<view class="label">{{item.homecareName}}</view>
				<view class="label">联系方式：{{item.phoneNo}}</view>
				<view class="label">上门时间：{{item.createTime || "无"}}</view>
				<view class="label">发表时间：{{item.visitTime}}</view>
				<view class="label">预付定金：{{item.deposit}}元</view>
				<view class="label">地区：{{item.area}}</view>
				<view class="label">地址：{{item.address}}</view>
				<view class="label">说明情况: {{item.description || "无"}}</view>
				<view class="btn margin50" @click="$tools.route('./done', item.id)">{{item.state==2? "剩余支付结清" : "查看详情"}}</view>
			</view>
		</template>
		<template v-if="status==4">
			<view class="box margin20 padding40" v-for="(item, index) in list" :key="index">
				<view class="label" style="padding-top: 0;">店铺名称：{{item.shopName}}</view>
				<view class="label">{{item.homecareName}}</view>
				<view class="label">联系方式：{{item.phoneNo}}</view>
				<view class="label">上门时间：{{item.createTime || "无"}}</view>
				<view class="label">发表时间：{{item.visitTime}}</view>
				<view class="label">预付定金：{{item.deposit}}元</view>
				<view class="label">地区：{{item.area}}</view>
				<view class="label">地址：{{item.address}}</view>
				<view class="label">说明情况: {{item.description || "无"}}</view>
			</view>
		</template>
		
		<u-empty text="列表为空" mode="list" v-if="list.length===0" margin-top="200"></u-empty>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				menuHeight: 0,
				status: "",
				list: []
			}
		},
		async onLoad(option) {
			this.status = option.value
			console.log(this.status)
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					that.menuHeight = Number(menuButtonInfo.height) * ( 750 / deviceWidth )
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
		},
		async onShow() {
			await this.getList()
		},
		
		methods: {
			async cancel(id){
				const res = await this.$request(`/api/WeChat/userHomecareCancel?orderId=${id}`, {}, "GET")
				if(res.code===200) {
					this.$u.toast("取消成功")
					this.getList()
				}
			},
		
			
			async getList(){
				console.log("kkkk")
				const res = await this.$request(`/api/WeChat/userHomecareOrderList?state=${this.status}`, {
					state: this.status
				}, 'GET')
				if(res.code===200) {
					console.log(res)
					this.list = res.data
					console.log("ppp", this.list)
				}
			}
		},
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
	}
	.box {
		width: 690rpx;
		min-height: 88rpx;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		position: relative;
		.label {
			color: #454545;
			line-height: 1;
			font-size: 30rpx;
			padding-top: 25rpx;
		}
		.btn {
			width: 520rpx;
			height: 88rpx;
			background: #D37430;
			border-radius: 12rpx;
			line-height: 88rpx;
			text-align: center;
			color: #fff;
		}
	}
</style>